<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html>
<head>
  <meta charset="UTF-8">
  <title>工资列表</title>
  <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/style.css">
</head>
<body>
<div class="container">
  <jsp:include page="/header.jsp" />
  <h2>工资列表</h2>

  <form action="${pageContext.request.contextPath}/SalaryServlet" method="get" class="search-form">
    <input type="hidden" name="action" value="list">
    员工姓名: <input type="text" name="searchEmpName" value="<c:out value='${searchEmpNameVal}'/>">
    <input type="submit" value="查询">
    <a href="${pageContext.request.contextPath}/SalaryServlet?action=list" class="button-link">显示全部</a>
  </form>
  <p><a href="${pageContext.request.contextPath}/SalaryServlet?action=new">录入新工资</a></p>

  <table>
    <tr>
      <th>ID</th>
      <th>员工姓名</th>
      <th>年份</th>
      <th>月份</th>
      <th>金额</th>
      <th>状态</th>
      <th>操作</th> <%-- 操作列现在总是显示 --%>
    </tr>
    <c:forEach var="sal" items="${listSalary}">
      <tr>
        <td>${sal.id}</td>
        <td><c:out value="${sal.empName}"/></td>
        <td>${sal.salaryYear}</td>
        <td>${sal.salaryMonth}</td>
        <td><fmt:formatNumber value="${sal.amount}" type="currency" currencySymbol="¥"/></td>
        <td><c:out value="${sal.status}"/></td>
        <td>
          <a href="${pageContext.request.contextPath}/SalaryServlet?action=edit&id=${sal.id}">编辑</a>
          | <a href="${pageContext.request.contextPath}/SalaryServlet?action=delete&id=${sal.id}&searchEmpName=<c:out value='${searchEmpNameVal}'/>"
               onclick="return confirm('确定删除这条工资记录吗？');">删除</a> <%-- 删除按钮现在总是显示 --%>
        </td>
      </tr>
    </c:forEach>
    <c:if test="${empty listSalary}">
      <tr><td colspan="7">没有找到相关工资记录。</td></tr>
    </c:if>
  </table>
</div>
</body>
</html>
